package niuke.week01;

import java.util.*;

/**
 * 给定两个有序数组arr1和arr2，再给定一个整数k，返回来自arr1和arr2的两个数相加和最大的前k个，两个数必须分别来自两个数组
 * 按照降序输出
 */
public class SumOfMaxnumber {
    static class Point {
        public int row;
        public int col;
        public int sum;

        public Point(int a1, int a2, int sum) {
            this.row = a1;
            this.col = a2;
            this.sum = sum;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Point point = (Point) o;

            if (row != point.row) return false;
            if (col != point.col) return false;
            return sum == point.sum;
        }

        @Override
        public int hashCode() {
            int result = row;
            result = 31 * result + col;
            result = 31 * result + sum;
            return result;
        }
    }

    public static void main(String[] args) {
        method1();
    }



    public static void method1(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int[] arr1 = new int[n];
        int[] arr2 = new int[n];

        for (int i = 0; i < n; i++)
            arr1[i] = sc.nextInt();

        for (int i = 0; i < n; i++)
            arr2[i] = sc.nextInt();

        PriorityQueue<Point> que = new PriorityQueue<>(n, new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2) {
                return o2.sum - o1.sum;
            }
        });

        HashSet<Point> set = new HashSet<>();
        Point point1 = new Point(n - 1, n - 1, arr1[n - 1] + arr2[n - 1]);
        que.add(point1);
        set.add(point1);
        int[] res = new int[k];
        int idx=0;
        while (idx!=k) {
            Point point = que.poll();

            res[idx++] = point.sum;

            Point point2 = new Point(point.col - 1, point.row, arr1[point.col - 1] + arr2[point.row]);
            if(point.col-1>0 && !set.contains(point2) ){
                que.add(point2);
                set.add(point2);
            }
            Point point3 = new Point(point.col, point.row - 1, arr1[point.col] + arr2[point.row - 1]);
            if(point.row-1>0 && !set.contains(point3) ){
                que.add(point3);
                set.add(point3);
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < k; i++) {
            sb.append(res[i]).append(" ");
        }
        System.out.println(sb.toString());
    }
}